from PyQt5.QtWidgets import QWidget, QVBoxLayout, QListWidget, QListWidgetItem
from PyQt5.QtGui import QIcon
from core.os_detector import OSDetector

class EntryList(QWidget):
    OS_ICONS = {
        "Windows": ":/icons/windows.png",
        "macOS": ":/icons/macos.png",
        "Linux": ":/icons/linux.png"
    }

    def __init__(self):
        super().__init__()
        self.layout = QVBoxLayout(self)
        self.entry_list = QListWidget()

        os_detector = OSDetector()
        for entry in os_detector.detect_os():
            icon_key = self._determine_os_type(entry["name"])
            icon_path = self.OS_ICONS.get(icon_key, ":/icons/linux.png")
            item = QListWidgetItem(QIcon(icon_path), entry["name"])
            self.entry_list.addItem(item)

        self.layout.addWidget(self.entry_list)

    def _determine_os_type(self, name):
        if "Windows" in name:
            return "Windows"
        elif "macOS" in name or "Mac" in name:
            return "macOS"
        else:
            return "Linux"